package com.weimob.mcloud.wechatwork.customer.config;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.weimob.mcloud.wechatwork.core.adapter.pojo.dto.campaign.response.CampaignCategoryConfigBO;
import com.weimob.mcloud.wechatwork.core.adapter.service.campaign.CampaignConfigService;
import com.weimob.soa.common.response.SoaResponse;
import com.weimob.soa.common.utils.SoaUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * 活动配置信息
 */
@Slf4j
@Component
public class CampaignApolloConfig {


    @Reference
    private CampaignConfigService campaignConfigService;

    /**
     * 根据productId+refer查询活动分类配置
     *
     * @param productId 产品ID
     * @param refer     活动对应refer
     * @return
     */
    public CampaignCategoryConfigBO getCampaignCategoryMapping(Long productId, String refer) {
        if (productId == null || StringUtils.isBlank(refer)) {
            log.warn("#CampaignApolloConfig.getCampaignCategoryMapping# productId or refer is null, productId:{}, refer:{}", productId, refer);
            return null;
        }
        SoaResponse<CampaignCategoryConfigBO, Void> soaResponse = campaignConfigService.getCampaignCategoryConfig(productId, refer);
        log.info("#CampaignApolloConfig.getCampaignCategoryMapping# call 'getCampaignCategoryConfig' method result, productId:{}, refer:{}, campaignCategoryMappingList:{}", productId, refer, JSON.toJSONString(soaResponse));
        if (!SoaUtil.isSucc(soaResponse)) {
            return null;
        }
        return soaResponse.getResponseVo();
    }


}
